// 发表评论组件
import React, { Component } from 'react'
import bear from '../images/bear.JPG' // 导入图片

class Forms extends Component {
  state = {
    txt: ''
  }
  txtRef = React.createRef()
  handleTxt = e => {
    this.setState({
      txt: e.target.value
    })
  }
  handleSubmit = () => {
    this.props.addComment(this.state.txt)
    // 清空内容
    this.setState({
      txt: ''
    })
    // 设置光标
    this.txtRef.current.focus()
  }
  render() {
    return (
      // 发表评论区
      <div className="comment-send-container">
        <div>
          <img className="user-head" src={bear} alt="头像" />
        </div>
        <div className="comment-send">
          <div className="textarea-container">
            <textarea
              ref={this.txtRef}
              cols="80"
              rows="5"
              placeholder="发条友善的评论"
              className="ipt-txt"
              value={this.state.txt}
              onChange={this.handleTxt}
            />
            <button className="comment-submit" onClick={this.handleSubmit}>
              发表评论
            </button>
          </div>
          <div className="comment-emoji">
            <i className="face"></i>
            <span className="text">表情</span>
          </div>
        </div>
      </div>
    )
  }
}

export default Forms
